

import 'package:safetymonitor/app/core/core.dart';

/// 自定义属性框（输入框、选择框）
///
/// eg：
/// ```dart
/// CustomField(
///  title: '职工姓名',
///  right: CustomField.input(
///    controller: controller.nameCtrl,
///    onChanged: (p0) {
///      controller.onSaveChanges();
///    },
///  ),
/// ),
/// ```
class CustomField extends StatelessWidget {
  const CustomField({
    required this.title,
    this.right,
    super.key,
    this.isRequired = false,
    this.bottom,
    this.titleStyle = const TextStyle(
      fontSize: 14,
      height: 1.2,
      color: Color(0xFF262F38),
      fontWeight: FontWeight.w400,
    ),
  });

  /// 标题
  final String title;

  /// 标题风格
  final TextStyle titleStyle;

  /// 右侧组件
  final Widget? right;

  /// 是否必须，如果为是，则标题前面会有一个红色的*号
  final bool isRequired;

  /// 底部组件
  final Widget? bottom;

  @override
  Widget build(BuildContext context) {
    final top = Row(
      children: [
        if (isRequired) const Text('*', style: TextStyle(color: Colors.red)),
        Text(
          title,
          style: titleStyle,
        ),
        AppGaps.hGap10,
        Expanded(
          child: Align(
            alignment: Alignment.centerRight,
            child: right,
          ),
        ),
      ],
    );
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 17.w, vertical: 7.w),
      height: bottom == null ? 44.w : null,
      child: bottom == null
          ? top
          : Column(
              children: [
                top,
                bottom!,
              ],
            ),
    );
  }
}
